package com.atxwq.shop.manager.controller;

import com.atxwq.shop.manager.serivce.CategoryBrandService;
import com.atxwq.shop.model.dto.product.CategoryBrandDto;
import com.atxwq.shop.model.entity.product.Brand;
import com.atxwq.shop.model.entity.product.CategoryBrand;
import com.atxwq.shop.model.vo.common.Result;
import com.atxwq.shop.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 品牌列表接口
 * @Date 2025/5/13 16:39
 * @Created by 12336
 */

@RestController
@RequestMapping("/admin/product/categoryBrand")
public class CategoryBrandController {
    @Autowired
    private CategoryBrandService categoryBrandService;

    /**
     * 分页+搜索查询分类品牌
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/{page}/{limit}")
    public Result findByPage(@PathVariable Integer page, @PathVariable Integer limit,
                             CategoryBrandDto categoryBrandDto){
        PageInfo<CategoryBrand> pageInfo = categoryBrandService.findByPage(page, limit, categoryBrandDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加品牌分类
     * @param
     * @return
     */
    @PostMapping("save")
    public Result save(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.save(categoryBrand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }



    /**
     * 修改品牌分类
     * @param
     * @return
     */
    @PutMapping("update")
    public Result update(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.update(categoryBrand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 删除品牌分类
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable Long id){
        categoryBrandService.delete(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /*================商品管理添加模块相关分类接口==================================*/

    /**
     * 根据商品关联的分类id查询品牌
     * @param categoryId
     * @return
     */
    @GetMapping("/findById/{categoryId}")
    public Result findById(@PathVariable Long categoryId){
        List<Brand> brandList = categoryBrandService.findById(categoryId);
        return Result.build(brandList, ResultCodeEnum.SUCCESS);
    }


}
